package top.jiangqiang.qyblog.portal.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.jiangqiang.qyblog.common.base.controller.BaseController;
import top.jiangqiang.qyblog.common.base.query.PageResult;
import top.jiangqiang.qyblog.common.base.response.Result;
import top.jiangqiang.qyblog.common.constant.RequestURLConstants;
import top.jiangqiang.qyblog.core.domain.dto.CategoryQueryDto;
import top.jiangqiang.qyblog.core.domain.vo.CategoryVo;
import top.jiangqiang.qyblog.core.service.ICategoryService;

/**
 * @author jiangqiang
 * @date 2022-11-27
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(RequestURLConstants.PUBLIC_CATEGORY_CONTROLLER_PREFIX)
@Tag(name = "文章分类接口")
public class PublicCategoryController extends BaseController {
    private final ICategoryService categoryService;

    @GetMapping
    @Operation(summary = "根据条件查询分类列表", description = "指定父级分类id后，只查询该分类下的直接子分类")
    public Result<PageResult<CategoryVo>> list(@Validated @ParameterObject CategoryQueryDto categoryQueryDto) {
        return categoryService.findByCondition(categoryQueryDto);
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询分类详情", description = "根据id查询分类")
    public Result<CategoryVo> get(@PathVariable Long id) {
        return categoryService.getCategory(id);
    }

}
